﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<%@include file="../../commons/meta.jsp"%>
<c:set var="baseUrl" value="${ctx}api/independent-recruit/" scope="request"/>
<link rel="stylesheet" href="${ctx}assets/plugins/pure/pure-min.css" media="all" />
<script type="text/javascript" src="${ctx}assets/plugins/plupload/2.2.1/js/plupload.full.min.js"></script>
<script type="text/javascript" src="${ctx}assets/plugins/plupload/2.2.1/js/i18n/zh_CN.js"></script>
<script type="text/javascript" src="${ctx}assets/assetadmin/js/major.js"></script>
</head>
<body>
    <%@include file="../../commons/head.jsp"%>
    <div class="content">
        <%@include file="../../commons/menu.jsp"%>
        <!--右侧展示部分-->
        <div class="right-zq">
            <!--center content-->
            <div class="dynamic">
                <form id="listForm" action="${ctx}api/independent-recruit/" method="post">
                    <div class="role dynamiclayer" style="display: block;">
                        <div class="title orange2">
                            <span class="left">高校信息管理</span><label> > </label><span>自主招生管理</span>
                        </div>
                        <div class="role-input">
                            <ul class="input">
                                <li class="p25">年份：<input type="text" name="searchMap.year,eq,string" placeholder="请输入年份" value="" class="input1" maxlength="4" /></li>
                                <li class="p50">学校名称：<input type="text" name="searchMap.collegeName,like,string" placeholder="请输入学校名称" value="" class="input1" maxlength="50" /></li>
                            </ul>
                            <div class="button">
                                <span class="orange2" onclick="listFormPageSearch(1)">查询</span>
                                <s:authorize access="hasAuthority('independent:recruit:add')">
                                    <span class="orange2"><a href="${ctx}api/independent-recruit/add">添加</a></span>
                                </s:authorize>
                            </div>
                        </div>
                        <div class="role-table role-table2">
                            <table cellspacing="0px" id="datatable">
                            </table>
                        </div>
                        <div class="role-page">
                            <input type="hidden" id="pageSize" name="pageSize" value="10" />
                            <ul id="datapagefoot">
                            </ul>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
<script type="text/javascript">
var defaultPageFoot = '';
defaultPageFoot += '<li><a class="first orange2-text" id="firstPage" href="javascript:void(0);">首页</a></li>';
defaultPageFoot += '<li>共<label class="num"  id="pagesPageCount">0</label>页，每页<label class="num">10</label>条，';
defaultPageFoot += '到第<input type="text" id="pageNumers" name="pageNumber" value="1" maxlength="9" onpaste="return false;" class="num" />页';
defaultPageFoot += '<span class="confirm orange2-text orange2-border"  onclick="listFormPageSearch(1)">确定</span></li>';

/** 分页查询 */
function listFormPageSearch(pageNum) {
 var pageForm = $("#listForm").serializeObject();
 var pageCounts = $("#pageCounts").val();
 checkPageNumber(pageForm, pageNum);

 var searchMap = [];
 $.each(pageForm, function (name, value) {
  if (name.indexOf('searchMap') >= 0) {
   var searchMapMeta = {};
   delete pageForm[name];
   var name2 = name.replace("searchMap.", "");
   searchMapMeta[name2] = value;
   searchMap.push(name2 + "," + value);
  }
 });
 pageForm.searchList = searchMap;
 // 默认按id排序
 pageForm.sort = "year";
 pageForm.order = "desc";
 
 var searchJsonUrl = 'api/independent-recruit/page.json';
 var pageData = JSON.stringify(pageForm);
 debugs("ajax pageData : " + pageData);
 var tableHead = ['序号','年份','学校','标题','创建时间','操作'];

 var tableHtml = getHead(tableHead);
 $.ajax({
  url: searchJsonUrl + "?rand=" + Math.random(),
  data: pageData,
  type: 'POST',
  contentType: "application/json",
  dataType: 'json',
  success: function (pages) {
    debugs(pages.rows);
   var base = pages.pageSize*(pages.pageNumber-1);
   var tr = "";
   $.each(pages.rows, function (index, item) {
    var trtmp = getValueTr([
     (base+index+1),
     filtUndef(item.year),
     filtUndef(item.collegeName),
     filtUndef(item.title),
     getTimeYMDHMSStr(item.createTime),
     <s:authorize access="hasAuthority('independent:recruit:update')">
     '<a href="javascript:void(0);" onclick="rowDetail(' + item.id + ')">编辑</a>&nbsp;&nbsp;' +
     </s:authorize>
     '<a href="javascript:void(0);" onclick="viewDetail(' + item.id + ')">详情</a>&nbsp;&nbsp;' +
     <s:authorize access="hasAuthority('independent:recruit:delete')">
     '<a href="javascript:void(0);" onclick="del(' + item.id + ')">删除</a>' +
     </s:authorize>
     '']);
    tr += trtmp;
   });
   if (isEmpty(tr)) {
    tr = "<tr><td colspan='" + tableHead.length + "' class='error'><fmt:message key='Temporarily.no.data'/></td></tr>";
   }

   $("#datatable").html(tableHtml + tr);
   $("#pageSize").val(pages.pageSize);
   $("#datapagefoot").html(getPageFoot(pages));
   // 解决当上次查询无数据时，弹出 “请输入合理的页码范围!”提示
   if ($("#pageCounts").val() == "0") {
    $("#pageCounts").val("");
   }
  }, error: function (xhr) {
   alertError("<fmt:message key='sys.message.searcherror'/>");// 请求失败遇到异常触发
   $("#datapagefoot").html(getDefaultPageFoot());
  }
 });
}

function rowDetail(id) {
  if (empty(id)) {
   alertError('请点击要查看的记录！');
   return false;
  }
  window.location.href = "${baseUrl}detail/" + id
 }

function viewDetail(id){
	if (empty(id)) {
		 alertError('请点击要查看的记录！');
		 return false;
	}
	//window.location.href = "${baseUrl}view/" + id;
	window.open("${baseUrl}view/" + id);
 }

function del(id) {
  var setIds = [];
  setIds.push(id);
  layer.confirm('确定要删除该条数据？', {
     btn: ['确定', '取消']
   , btn2: function (index, layero) {
      layer.close(index);
   }, title: ['删除提示', true]
  }, function (index, layero) {
     rowDelete(setIds);
  });
 }

 function rowDelete(id) {
  debugs(id);
  $.ajax({
   url: "${ctx}api/independent-recruit/remove",
   type: 'POST',
   contentType: "application/json",
   dataType: 'json',
   data: JSON.stringify({"ids": id}),
   success: function (data) {
    debugs(data);
    if (data != null && data.flag) {
      layer.alert(
          '删除成功', 
          {
              icon: 1,
              skin: 'layer-ext-moon',
              closeBtn: 0
          },
          function(){
              $('#listForm').submit();
          }
      );
    } else {
      alertError('删除失败');
    }
   }
  });
 }

 // 初始化时加载分页数据。
 listFormPageSearch(1);
</script>
<%@include file="../../commons/footpop.jsp"%>
</body>
</html>
